<?php

require_once( '../system/smarty.inc' );

require_once( '../system/mdao/Class_M_MAP_SERVICE.php' );
require_once( '../system/mdao/Class_M_OTHER.php' );

require_once( '../system/Class_ERROR.php' );
require_once( '../system/login.inc.php' );
require_once( '../system/aoki_m.php' );
require_once( '../system/Class_PWD.php' );

Class_PWD::valid_auth(AOKI_AUTH_MAP_SERVICE,$login['staff_auth']);
$isG7  = FALSE;
if   ($login['staff_auth'] == 'G-7') {
	$isG7 = TRUE;
}
$smarty->assign('isG7', $isG7 );
$dosearch = FALSE ;
$dao = new Class_M_MAP_SERVICE;

if ( isset( $_GET['csv'] ) &&  (  $_GET['csv'] == "download" ) ||
	 isset( $_GET['hist'] ) &&  (  $_GET['hist'] == "2" ) ) {
	$forms =  $_SESSION['MSEARCH']['MAP_SERVICE'];
}else {
	$forms = $_GET;
	$_SESSION['MSEARCH']['MAP_SERVICE'] = $forms;
}

$wherearr =  array();

/*
if ( isset( $forms['mservice_cd'] ) &&  ( !empty( $forms['mservice_cd'] ) ) ){
	$wherearr[] = sprintf(" mservice_cd =  '%s' ",  $forms['mservice_cd'] );
}
*/

if ( isset( $forms['mservice_name'] ) &&  ( !empty( $forms['mservice_name'] ) ) ){
	$wherearr[] = sprintf(" mservice_name like  '%s' ",  "%".$forms['mservice_name']."%" );
}



//---CSVダウンロード　処理開始
if ( isset( $_GET['csv'] ) &&  (  $_GET['csv'] == "download" ) ){
	$_GET["csv"] = "";
	$tmpfilename = "ins_mservice".date("Ymd_His");
	header("Content-Type: application/octet-stream"); 
	header("Content-Disposition: attachment; filename=$tmpfilename.csv");
	$data = $dao->search( $wherearr );
	$colums = array();
	//列名
	$colums["name"] = array('mservice_cd','mservice_name','u_time','m_user_name');
	$colums["type"] = array();
	foreach ($colums as $k => $v) {
		$colums["type"][$v] = 1;
	}
	//$colums["type"]["insert_conums"] = 2;
	
	
	$dao->output_csv($data, $colums);
	exit;
}
//---CSVダウンロード　処理完了

if ( isset( $forms['search'] ) && (  !empty( $forms['search'] ) ) ){
	$dosearch = TRUE;
}

if( isset( $forms['page'] ) && is_numeric( $forms['page'] ) ){
	$dosearch = TRUE;
	$page['current'] = $forms['page'];	
}else{
	$page['current'] = 1;
}
$page['item'] = PAGE_MAX;
if ($dosearch) {
	//$page内容は関数内部更新されます。
	$data = $dao->search( $wherearr, $page );
}

if( isset($forms) ) $smarty->assign('forms', $forms);
if( isset($data) )  $smarty->assign('data', $data);
if( isset($page) )  $smarty->assign('page', $page);


$smarty->assign('menu',  $smarty->fetch('menu.html') );
$smarty->assign('logout', $smarty->fetch('logout.html') );
$smarty->assign('footer', $smarty->fetch('footer.html') );
$smarty->assign('pageing', $smarty->fetch('page.html') );
$smarty->display('mmservice_index.html');

?>